<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/13
 * Time: 11:34
 */
namespace App\Http\Middleware;
use App\Model\Members;
use Closure;
use Illuminate\Support\Facades\Session;

class HomeLogin
{
    public function handle($request, Closure $next)
    {
//        dd(session()->all(),session('session_username'));
        $homeUser=session('home_user');
        if (empty($homeUser)){
            return redirect('/home/login/login')->withErrors('你还未登录请先登录');
        }
        $sessionId=Members::where(['uid'=>$homeUser['uid']])->value('session_id');
        if (Session::getId() != $sessionId) {
            return redirect('/home/login/login')->withErrors('系统在别处登录!');
        }
        $response = $next($request);

        // 执行动作

        return $response;
    }

}